/*
2011/3/4 21:20:16
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LanSunSystem
{
    public partial class ExTableList : LanSunSystem.BaseControl
    {
        public override void SubMenu_Click(object sender, EventArgs e)
        {
            try
            {
                base.SubMenu_Click(sender, e);
                ToolStripMenuItem a = (ToolStripMenuItem)sender;
                string EventKey = a.Name;
                bool NeedReturn = false;
                object m_QueryCond = null;
                DataRow dwBaseQuery = null;
                string basetable = ""; 
                DataRow dwTableList = dwCurrentRecord;
                bool HandleByBase = false;
                switch (EventKey)
                {
                    case "OnFileNewRecord":
                        mnu_FileNewItem_Click(this, null);
                        dwTableList = dwCurrentRecord;
                        dwBaseQuery = dwTableList;
                        break;
                    case "OnFileCopyRecord":
                        mnu_FileCopyItem_Click(this, e);
                        dwTableList = dwCurrentRecord;
                        dwBaseQuery = dwTableList;
                        break;
                     case "OnCreateByQuery":
                        m_QueryCond = new ExTableListQueryCond();
                        basetable = ((BaseControl)m_QueryCond).BaseTable;
                        //dwBaseQuery = MapDataRow("CreateByQuery", "TableName", basetable, dwCurrentRecord,null,null);
                        
                        dwBaseQuery = MapDataRow("CreateByQuery", "IX_"+BaseTable, basetable, dwCurrentRecord, null, null);
						
                        break;
                    case "OnCreateByQueryFinish":
                        break;
                    case "OnValidateRecord":
                        NeedReturn = true;
                        dwTableList = dwCurrentRecord;
                        dwBaseQuery = dwTableList;
                        break;
                     default:
                        HandleByBase = true;
                        break;
                }
                if (!HandleByBase)
                {
                    RequestMessage.NeedReturn = NeedReturn;
                    DataSetEvent = this.ImportDataTable(DataSetEvent, dwBaseQuery);
                    HandleSubMenuNode(EventKey, this.RequestMessage, DataSetEvent);
                }
            }
            catch (Exception ex)
            {
                this.m_log.Error(ex);
            }
        }
        public ExTableList()
        {
            InitializeComponent();
            BaseTable = "TableList";
            this.FormType = "DataForm";
            LinkEvent();
        }
        private void LinkEvent()
        {
        }
        public override void mnu_FileNewItem_Click(object sender, EventArgs e)
        {
            try
            {
                dwCurrentRecord = dtBaseTable.Rows.Add();
                dwCurrentRecord["SysID"] = this.SysID;
                dwCurrentRecord["LongDes"] = ("TableList" + DateTime.Now.TimeOfDay.ToString());
                dwCurrentRecord["ShortDes"] = dwCurrentRecord["LongDes"].ToString().Substring(0, 20);
                dwCurrentRecord.AcceptChanges();
            }
            catch (Exception ex)
            {
                m_log.Error(ex);
            }
        }
                public override void mnu_FileCopyItem_Click(object sender, EventArgs e)
        {
            try
            {
                base.mnu_FileCopyItem_Click(sender, e);
                  if (dwCurrentRecord.Table.Columns.Contains("GoodsKeyID"))
                {
                    dwCurrentRecord["GoodsKeyID"] = "";
                }
                dwCurrentRecord.AcceptChanges();
            }
            catch (Exception ex)
            {
                m_log.Error(ex);
            }

        }
        public override void mnu_FileSaveItem_Click(object sender, EventArgs e)
        {
            try
            {
                dwCurrentRecord.AcceptChanges();
                DataSet dsRequest = new DataSet();
                MsgRequest.JobID = "OnSaveRecord";
                Queue TargetTableList = new Queue();

				TargetTableList.Enqueue(BaseTable);
                string TableName = "";
                while (TargetTableList.Count > 0)
                {
                    DataTable dtTemp = null;
                    TableName = TargetTableList.Dequeue() as string;
                    if (BaseDataSet.Tables.Contains(TableName))
                    {
                        dtTemp = BaseDataSet.Tables[TableName];
                        if (dtTemp != null)
                        {
                            dsRequest = ImportDataTable(dsRequest, dtTemp);
                        }
                    }
                }
                MsgRequest.dsRequest = dsRequest;
                m_MsgReturn = ((IERPBLayerService)BLClient).AskService(MsgRequest);
            }
            catch (Exception ex)
            {
                m_log.Error(ex);
            }
        }
  #region Windows Form Designer generated code
      
       
            /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // ExTableList
            // 
            this.Name = "ExTableList";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion
    
    }
    
}
namespace LanSunSystem
{
    public partial class ExTableListQueryCond : LanSunSystem.BaseControl
    {
        public override void SubMenu_Click(object sender, EventArgs e)
        {
            try
            {
                base.SubMenu_Click(sender, e);
                ToolStripMenuItem a = (ToolStripMenuItem)sender;
                string EventKey = a.Name;
                bool NeedReturn = false;
                DataSetEvent = new DataSet();
                DataRow dwTableListQueryCond = null;
                DataRow dwBaseQuery = null;
                bool HandleByBase = false;
                switch (EventKey)
                {
                     case "OnCreateByQuery":
                        break;
                    case "OnCreateByQueryFinish":
                        this.mnu_FileQueryItem_Click(this, null);
                        dwTableListQueryCond = dwCurrentRecord;
                        dwBaseQuery = dwTableListQueryCond;
                        foreach (DataTable dtTemp in this.RequestMessage.dsReturn.Tables)
                        {
                            DataSetEvent = this.ImportDataTable(DataSetEvent, dtTemp);
                         }
                        
                      
                        break;
                    default:
                        HandleByBase = true;
                        break;
                }
                if (!HandleByBase)
                {
                    RequestMessage.NeedReturn = NeedReturn;
                    DataSetEvent = this.ImportDataTable(DataSetEvent, dwBaseQuery);
                    HandleSubMenuNode(EventKey, this.RequestMessage, DataSetEvent);
                }
            }
            catch (Exception ex)
            {
                this.m_log.Error(ex);
            }
        }
        #region Windows Form Designer generated code
        public ExTableListQueryCond()
        {
            InitializeComponent();
            this.BaseTable= "TableListQueryCond";
            this.FormType = "QueryCondition";
        }
        
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

      

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // ExTableListQueryCond
            // 
            this.Name = "ExTableListQueryCond";
            
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion
     }
}
